var webPath = "";
$(document).ready(function(){
	webPath = $("#webPath").val();
	var msg = $("#message").val();
	if(msg != ""){
		alert(msg);
	}
	
	$("#submit_btn").click(submit);
});

function changeValidateCode(){
	var timenow = new Date().getTime();
	$("#vImg").attr("src", webPath+"/rand?d="+timenow);
}

function changeServLine(val){
	var data = {"servLineId": val};
	$.ajax({
		type: "POST",
		cache: false,
		dataType: "json",
		url: webPath+"/complaint!changeServline.action",
		data: data,
		success: function(json){
			if(json != null && json.subServLineLs != null && json.subServLineLs.length > 0){
				var strHtml = '';
				$.each(json.subServLineLs,function(i,value){
					strHtml += showSubLine(value);
				});
				$("#id_servSubline").html(strHtml);
			}else{
				alert("服务子条线查询失败！");
			}
		}
	});
}

function showSubLine(value){
	var servSubline = value.servSubline;
	var servSublineName = value.servSublineName;
	var strHtml = '<option value="'+servSubline+'">'+servSublineName+'</option>';
	return strHtml;
}

function submit(){
	var author  = $("#id_author").val();
	var idcard  = $("#id_idcard").val();
	var phone   = $("#id_phone").val();
	var email   = $("#id_email").val();
	var authorAddr = $("#id_authorAddr").val();
	var queAddr = $("#id_queAddr").val();
	var content = $("#id_queContent").val();
	var vcode   = $("#id_vcode").val();
	
	if(string.trim(author) == ""){
		alert("请输入姓名！");
		$("#id_author").focus();
		return false;
	}
	if(string.trim(idcard) != ""){
		if(!string.isIDcard(idcard)){
			alert("身份证号码不正确！");
			$("#id_idcard").select();
			return false;
		}
	}else{
		alert("请输入身份证号码！");
		$("#id_idcard").select();
		return false;
	}
	if(!string.isPhone(phone)){
		alert("手机号码格式不正确！");
		$("#id_phone").select();
		return false;
	}
	if(string.trim(email) != ""){
		if(!string.isEmail(email)){
			alert("电子邮箱格式不正确！");
			$("#id_email").select();
			return false;
		}
	}
	if(string.trim(authorAddr) == ""){
		alert("请输入家庭地址！");
		$("#id_authorAddr").focus();
		return false;
	}
	if(string.trim(queAddr) == ""){
		alert("请输入投诉上报地址！");
		$("#id_queAddr").focus();
		return false;
	}
	if(string.trim(content) == ""){
		alert("请输入投诉上报内容！");
		$("#id_queContent").select();
		return false;
	}else{
		var clength = string.length(content);
		if(clength > 200){
			alert("投诉上报内容过长，您现在输入了"+clength+"字符，不能超过200个字符！");
			$("#id_queContent").select();
			return false;
		}
	}
	if(string.trim(vcode).length < 4){
		alert("验证码输入有误！");
		$("#id_vcode").select();
		return false;
	}
	document.form1.submit();
}